package com.stars.controller.sysicons;
import com.stars.entity.sysicons.SysIconsEntity;
import com.stars.services.sysicons.SysIconsAccessServices;
import com.stars.services.sysicons.SysIconsConfigServices;
import com.stars.entity.dto.sysicons.SysIconsDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
/**
 * @Title: 图标管理 mybatis dao
 * @author dj
 * @date 2019-10-18 22:36:24
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/sysIconsCtl")
@Api(tags ="图标管理")
public class SysIconsCtl extends BaseController{
   @Autowired
   private SysIconsAccessServices  sysIconsAccessServicesImpl;
   @Autowired
   private SysIconsConfigServices  sysIconsConfigServicesImpl;

   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "图标管理"+BaseMsg.MODULAR_PAGE,notes ="图标管理"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "图标管理"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<SysIconsDTO> pageSysIconsList(Integer pageNum, Integer pageSize, SysIconsDTO dto,HttpServletRequest request) throws Exception{
        return sysIconsAccessServicesImpl.pageList(pageNum,pageSize,dto);

   }

    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "图标管理"+ BaseMsg.MODULAR_ADD,notes = "图标管理"+BaseMsg.MODULAR_ADD)
    @Log(detail = "图标管理"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg addSysIcons(@Validated({AddView.class}) SysIconsEntity entityName,HttpServletRequest request) throws Exception{
        
        return sysIconsConfigServicesImpl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "图标管理"+ BaseMsg.MODULAR_UPDATE,notes = "图标管理"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "图标管理"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg updateSysIcons(@Validated({UpdateView.class}) SysIconsEntity updateEntityDto,HttpServletRequest request) throws Exception{
        SysIconsEntity entity = sysIconsAccessServicesImpl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.UPDATE);
        return sysIconsConfigServicesImpl.updateSelectiveById(entity);
    }

    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "图标管理"+ BaseMsg.MODULAR_FIND_ID,notes = "图标管理"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "图标管理"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg findSysIconsById(String id) throws Exception{
        SysIconsEntity entityName = sysIconsAccessServicesImpl.selectById(id);
         return ResultMsg.success(entityName);
    }

     /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "图标管理"+BaseMsg.MODULAR_DEL,notes ="图标管理"+BaseMsg.MODULAR_DEL)
     @Log(detail ="图标管理"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg delSysIconsById(String ids) throws Exception{
        return sysIconsConfigServicesImpl.deleteByIds(ids.split(","));
     }

}